<template>
  <div class="topnav">
    <div class="logo">
      <router-link to="/">
        <svg class="icon">
          <use xlink:href="#icon-wangguan"></use>
        </svg>
      </router-link>
    </div>
    <ul class="menu">
      <router-link to="/doc">文档</router-link>
    </ul>
    <svg
      v-if="toggleMenuButtonVisible"
      class="toggleAside"
      @click="onToggleAside"
    >
      <use xlink:href="#icon-caidanzhankai"></use>
    </svg>
  </div>
</template>

<script lang="ts">
import { inject } from 'vue'
export default {
  props: {
    toggleMenuButtonVisible: {
      type: Boolean,
      default: false,
    },
  },

  setup() {
    const asideVisible = inject<Ref<boolean>>('asideVisible')
    const onToggleAside = () => {
      asideVisible.value = !asideVisible.value
    }
    return { onToggleAside }
  },
}
</script>

<style lang="scss" scoped>
.topnav {
  display: flex;
  padding: 16px;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 10;
  justify-content: center;
  align-items: center;
  > .logo {
    max-width: 6em;
    margin-right: auto;
    svg {
      width: 32px;
      height: 32px;
    }
  }
  > .menu {
    display: flex;
    white-space: nowrap;
    flex-wrap: nowrap;
    color: #fff;
    > li {
      margin: 0 1em;
    }
  }
  > .toggleAside {
    display: inline-block;
    width: 24px;
    height: 24px;
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    display: none;
    cursor: pointer;
    z-index: 20;
  }
  @media (max-width: 500px) {
    > .menu {
      display: none;
    }
    > .logo {
      margin: 0 auto;
    }
    > .toggleAside {
      display: inline-block;
    }
  }
}
</style>
